import {
  getConversionList,
  getTotalConversionList,
} from '../../services/channel/api';


export default {
  namespace: 'conversionData',

  state: {

    loading: true,
    converData: {
      list: [],
      pagination:{}
    },

  },

  effects: {

    *fetchGetConversionList({payload, callback}, { call, put }) {
      const response = yield call(getConversionList, payload);

      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: {
            converData: {
              list: response.data.records,
              pagination:{
                current: response.data.current,
                total: response.data.total,
              }
            },

          },
        });
        if (callback) callback();
      }
    },
    *fetchGetTotalConversionList({payload, callback}, { call, put }) {
      const response = yield call(getTotalConversionList, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: {converAllData: response.data},
        });
        if (callback) callback();
      }
    },
    
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },

};
